home *** CD-ROM | disk | FTP | other *** search
- /*
- Basie's Browser
- text display from text file
-
- 1993.6.27 v1.0
- copyright Y.Ouchi
-
- */
-
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include <register.h>
- #include "egb.h"
- #include "mos.h"
- #include "snd.h"
- #include "bb.h"
- #include "color.h"
-
- /* 関数プロトタイプ宣言 */
- int intreal(int, union REGS *, union REGS *, struct SREGS *);
- extern int textdsp(char *,int,char **,struct logcontent *,short *,int *);
- extern void linedsp(int, int, char *);
- extern void box(int, int, int, int, int, int);
- extern int logcheck ( char *, int, char **, struct logcontent *, short *);
- extern int titlemod(char *,int,char **,struct logcontent *,short *,int *);
- extern void mesout ( int );
- extern char *filesel ( void );
- extern void parmode(struct logcontent *, short *);
- void initial ( void );
- void initial_panel ( void );
-
- char egbwork[EGBWorkSize];
- char moswork[MosWorkSize];
- int max_title;
- int max_text;
- int max_content;
- int max_textn;
- int max_textp;
- int dispmode;
- static FILE *logFp;
- static char logfile[128]={""};
- static char *normalmode={"normal"};
- static char *parentmode={"parent"};
-
- void main( int ac, char **av )
- {
- char *file_read_mes={"now file reading"};
- char *ext_char={".bak"};
- char *logtext;
- char **disp_title;
- short *disptextn;
- short *disptextp;
- short *disptext;
- int i,textno;
- int contf,back;
- int ext_ptr;
- int nowtext;
- char bupfile[128];
- size_t logtextleng;
- struct logcontent *intext;
- static int parmodedone=0;
-
- /* input log file name check */
- if (ac>=2) {
- strcpy ( logfile, av[1] ) ;
- }
-
- /* initial display mode (parent mode) set */
- dispmode=PARENT_MODE;
-
- /* initialize */
- initial();
-
- EGB_writePage(egbwork,1);
- box(390,464,440,478,MODE_BACK_COL,1);
- EGB_color(egbwork, 0, MODE_COL);
- linedsp(391,478,parentmode);
- EGB_writePage(egbwork,0);
- EGB_color(egbwork, 0, TEXT_COL);
-
- if (strlen(logfile)==0) strcpy (logfile,filesel());
-
- while (strlen(logfile)!=0){
-
- /* log file read */
- /* file name separater change */
- /* backup file name make (original+.bak) */
- EGB_writePage(egbwork,1);
- box(268,0,639,16,TITLEBACK_COL,1);
- EGB_color(egbwork, 0, TITLE_COL);
- linedsp(268,15,logfile );
- EGB_writePage(egbwork,0);
- ext_ptr=0;
- for (i=0;i<strlen(logfile);i++){
- if (logfile[i]==0x2e) ext_ptr=i;
- if (logfile[i]==0x5c) logfile[i]=0x2f;
- }
- if (ext_ptr==0){
- strcpy(bupfile,logfile);
- strcat(bupfile,ext_char);
- }
- else{
- strncpy(bupfile,logfile,ext_ptr);
- bupfile[ext_ptr]=0x00;
- strcat(bupfile,ext_char);
- }
-
- /* memory get and file read */
- /* memory get for log analize & title display */
-
- (int)logtextleng=_get_file_size(logfile);
-
- if ( (int)logtextleng < 0 ){
- mesout ( FILE_ERROR );
- MOS_end();
- exit(0);
- }
-
- if ( (logtext=malloc(logtextleng+20))==NULL){
- mesout ( MEMORY_ERROR );
- MOS_end();
- exit(0);
- }
- if (logtextleng<60000) logtextleng=60000;
- max_text=logtextleng/500;
- max_content=logtextleng/500;
- max_title=logtextleng/2000;
- if ((intext=malloc(sizeof(int)+sizeof(struct textcontent *)))==NULL ){
- mesout(MEMORY_ERROR);
- MOS_end();
- exit(0);
- }
- if ( (intext->text=malloc(sizeof(union content)*max_content))==NULL ){
- mesout(MEMORY_ERROR);
- MOS_end();
- exit(0);
- }
- if ( (disptextn=malloc(sizeof(short)*max_text))==NULL ){
- mesout(MEMORY_ERROR);
- MOS_end();
- exit(0);
- }
- if ( (disptextp=malloc(sizeof(short)*max_text))==NULL ){
- mesout(MEMORY_ERROR);
- MOS_end();
- exit(0);
- }
- if ( (disp_title=malloc(sizeof(void *)*max_title))==NULL ){
- mesout(MEMORY_ERROR);
- MOS_end();
- exit(0);
- }
- for (i=0;i<max_title;i++){
- if ( (disp_title[i]=malloc(sizeof(char)*90))==NULL ){
- mesout(MEMORY_ERROR);
- MOS_end();
- exit(0);
- }
- }
-
- logFp=fopen( logfile, "rb" );
- if ( logFp == NULL ) {
- mesout ( FILE_ERROR );
- MOS_end();
- exit(0);
- }
-
- MOS_sysIcon(82,16,16,0);
- MOS_color( 0,12 );
- MOS_setpos(320,200);
- MOS_disp(1);
- EGB_writePage(egbwork,0);
- EGB_color(egbwork, 0, TEXT_COL);
- linedsp(256,290,file_read_mes);
-
- logtextleng=fread(logtext,1,logtextleng,logFp);
- fclose ( logFp );
- for (i=0;i<15;i++) logtext[logtextleng+i]=0x00;
-
- MOS_sysIcon(170,0,0,0);
- MOS_disp(0);
- MOS_color( 0,ARROW_COL );
- EGB_color(egbwork, 0, BACK_COL);
- EGB_clearScreen(egbwork);
- EGB_color(egbwork, 0, TEXT_COL);
-
- EGB_writePage(egbwork,0);
-
- if (logcheck(logtext,logtextleng,disp_title,intext,disptextn) != 0){
- if (dispmode==NORMAL_MODE){
- disptext=disptextn;
- max_text=max_textn;
- }
- else{
- parmode(intext,disptextp);
- parmodedone=1;
- for (i=0;i<max_textp;i++)
- if(intext->text[disptextp[i]].text.id!=TITLE_ID) break;
- if (i==0) i=1;
- disptext=&disptextp[i-1];
- max_text=max_textp-(i-1);
- }
- textno=0;
- contf=1;
- back=0;
-
- while ( contf ){
-
- /* text display */
-
- switch(textdsp(logtext,(int)logtextleng,disp_title,intext,
- disptext,&textno)){
- case 0 : /* all quit */
- contf=0;
- free(logtext);
- for (i=0;i<max_title;i++) free(disp_title[i]);
- free(disp_title);
- free(intext->text);
- free(intext);
- free(disptextn);
- free(disptextp);
- parmodedone=0;
- logfile[0]=0x00;
- break;
- case 1 : /* log save & quit */
- rename(logfile,bupfile);
- logFp=fopen( logfile, "wb" );
- if ( logFp == NULL ) {
- mesout(FILE_ERROR);
- MOS_end();
- exit(0);
- }
- clearerr(logFp);
- nowtext=disptext[textno];
- if(intext->text[nowtext-1].text.id==TITLE_ID){
- nowtext--;
- }
- fwrite((void *)&logtext[intext->text[nowtext].text.pos]
- ,1,logtextleng-(intext->text[nowtext].text.pos),
- logFp);
- if (ferror(logFp)!=0) mesout(FILE_ERROR);
- fclose(logFp);
- contf=0;
- for (i=0;i<max_title;i++) free(disp_title[i]);
- free(disp_title);
- free(intext->text);
- free(intext);
- free(logtext);
- free(disptextn);
- free(disptextp);
- parmodedone=0;
- logfile[0]=0x00;
- strcpy (logfile,filesel());
- break;
- case 2 : /* title mode */
- EGB_clearScreen(egbwork);
- titlemod(logtext,(int)logtextleng,
- disp_title,intext,disptext,&textno);
- back=0;
- break;
- case 3 : /* new file select */
- EGB_clearScreen(egbwork);
- free(logtext);
- for (i=0;i<max_title;i++) free(disp_title[i]);
- free(disp_title);
- free(intext->text);
- free(intext);
- free(disptextn);
- free(disptextp);
- parmodedone=0;
- logfile[0]=0x00;
- strcpy (logfile,filesel());
- contf=0;
- break;
- case 4 : /* mode change */
- nowtext=disptext[textno];
- EGB_clearScreen(egbwork);
- EGB_writePage(egbwork,1);
- box(390,464,440,478,MODE_BACK_COL,1);
- EGB_color(egbwork, 0, MODE_COL);
- if (dispmode==NORMAL_MODE){
- if(parmodedone==0){
- parmode(intext,disptextp);
- parmodedone=1;
- }
- for (i=0;i<max_textp;i++)
- if(intext->text[disptextp[i]].text.id!=TITLE_ID)
- break;
- if (i==0) i=1;
- disptext=&disptextp[i-1];
- max_text=max_textp-(i-1);
- dispmode=PARENT_MODE;
- linedsp(391,478,parentmode);
- }
- else{
- dispmode=NORMAL_MODE;
- disptext=disptextn;
- max_text=max_textn;
- linedsp(391,478,normalmode);
- }
- EGB_writePage(egbwork,0);
- EGB_color(egbwork, 0, TEXT_COL);
- for (textno=max_text-1;textno>0;textno--)
- if (nowtext==disptext[textno]) break;
- back=0;
- break;
- case 5 : /* console */
- system("f:");
- system("cd \rbin");
- system("aricon");
- initial_panel ( );
- back=0;
- break;
- }
- }
- }
- else{
- mesout( LOG_ERROR );
- EGB_clearScreen(egbwork);
- free(logtext);
- for (i=0;i<max_title;i++) free(disp_title[i]);
- free(disp_title);
- free(intext->text);
- free(intext);
- free(disptextn);
- free(disptextp);
- parmodedone=0;
- logfile[0]=0x00;
- strcpy (logfile,filesel());
- }
- }
- MOS_end();
- exit(0);
- }
-
- /*
- initial set
- */
-
- void initial(void)
- {
- char para[50];
- union REGS in;
- struct SREGS seg;
- int i;
-
- /* initialization */
-
- /* key board initialize */
-
- in.h.ah = 0x05;
- in.h.al = 0x01;
- intreal(0x90, &in, &in, &seg);
-
- EGB_init(egbwork,EGBWorkSize);
- EGB_resolution(egbwork,0,3);
- EGB_resolution(egbwork,1,3);
- EGB_displayPage(egbwork,1,3);
-
- /* screen initialize */
- EGB_textZoom(egbwork,0,8,16);
- EGB_textZoom(egbwork,1,16,16);
-
- EGB_writePage(egbwork,0);
-
- DWORD(para + 0) = palno;
- for (i=0;i<palno;i++){
- DWORD(para + 8*i+4) = colpal[i][0];
- BYTE(para + 8*i+ 8) = colpal[i][3];
- BYTE(para + 8*i+ 9) = colpal[i][1];
- BYTE(para + 8*i+10) = colpal[i][2];
- BYTE(para + 8*i+11) = 0;
- EGB_palette(egbwork,1,para);
- }
- EGB_color(egbwork, 1, BACK_COL);
- EGB_clearScreen(egbwork);
-
- EGB_writePage(egbwork,1);
-
- DWORD(para + 0) = palno;
- for (i=0;i<palno;i++){
- DWORD(para + 8*i+4) = colpal[i][0];
- BYTE(para + 8*i+ 8) = colpal[i][3];
- BYTE(para + 8*i+ 9) = colpal[i][1];
- BYTE(para + 8*i+10) = colpal[i][2];
- BYTE(para + 8*i+11) = 0;
- EGB_palette(egbwork,1,para);
- }
- EGB_color(egbwork, 1, 0);
- EGB_clearScreen(egbwork);
-
- EGB_displayPage(egbwork,1,3);
-
- MOS_start(moswork,MosWorkSize);
- MOS_resolution( 0,3 );
- MOS_writePage( 1 );
- MOS_color( 0,ARROW_COL );
-
- SND_elevol_all_mute( 0xff );
- SND_elevol_set( 1, 127, 127 );
-
- initial_panel( );
-
- return;
- }
-
- /*
- initial display panel set
- */
-
- void initial_panel(void)
- {
- char *headtitle={" file name ="};
- char *name={"B-Browser V1.1"};
-
- EGB_writePage(egbwork,1);
- EGB_color(egbwork, 1, 0);
- EGB_clearScreen(egbwork);
- box(0,0,639,34,TITLEBACK_COL,1);
- box(0,462,639,479,TITLEBACK_COL,1);
- EGB_color(egbwork, 0, TITLE_COL);
- linedsp(20,15,headtitle );
- EGB_color(egbwork, 0, NAME_COL);
- EGB_fontStyle(egbwork, 1);
- linedsp(20,15,name );
- EGB_fontStyle(egbwork, 0);
- EGB_color(egbwork, 0, TEXT_COL);
- EGB_color(egbwork, 1, BACK_COL);
- EGB_writePage(egbwork,0);
- EGB_clearScreen(egbwork);
- return;
- }
-
-